package com.gitee.wsl.net.server.role.admin

import com.gitee.wsl.security.password.Password


/**
 * Exposed entity
 */
class AdminEntity(val id: Int,
                  var email :String,
                  var password :String,
                  var role:AdminRole
)

interface AdminsService {
    /**
     * Get count entities
     */
    fun countAdmins(): Int

    /**
     * Get all entities
     */
    fun getAll(): List<AdminEntity>

    /**
     * Find entity by id
     */
    fun findById(
        id: Int
    ):AdminEntity

    /**
     * Find entity by email
     */
    fun findByEmail(
        email: String
    ):AdminEntity

    /**
     * Get entity with check password for auth
     */
    fun findUserByAuth(
        email: String?,
        password: String?
    ):AdminEntity

    /**
     * Create entity
     */
    fun insert(
        email: String,
        role: AdminRole,
        password: String,
    )

    /**
     * Update entity
     */
    fun AdminEntity.update(
        role: AdminRole,
        password: String?,
    ) = let { entity ->
        entity.role = role
        password?.let { if (it.isNotBlank()) entity.password = Password.encode(it) }
        entity
    }


}